float readChannel(ADS1115_MUX channel)
{
    float voltage = 0.0;
    adc.setCompareChannels(channel);
    voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
    return voltage;
}
float v_to_TMP(float vo, float vi)
{
    float R1 = 9600.0;
    // 5.025 2.454;
    float R = vo * R1 / (vi - vo);
    R = R / 1000;
    float T = -0.0020 * R * R * R + 0.1678 * R * R - 5.4817 * R + 65.3095;
    T = T - 3.5;
    return T;
}

float v_to_PH(float vi)
{
    float v700 = 3.00;
    float v401 = 3.534;
    float dph = 2.99 / (v700 - v401);
    return dph * (vi - v700) + 7.0;
}

void readADC()
{
    adc_v[0] = readChannel(ADS1115_COMP_0_GND);
    adc_v[1] = readChannel(ADS1115_COMP_1_GND);
    adc_v[2] = readChannel(ADS1115_COMP_2_GND);
    adc_v[3] = readChannel(ADS1115_COMP_3_GND);
    char buf[80];
    //sprintf(buf, "%.3f\t%.3f\t%.3f\t%.3f", adc_v[0], adc_v[1], adc_v[2], adc_v[3]);
    //Serial.println(buf);
    //sprintf(buf, "PH=%.2f\tTMP=%05.2f", PH,TMP);
    //Serial.println(buf);
    float a = v_to_TMP(adc_v[0], adc_v[1]);
    if (a <= 120 && a >= -40)
        TMP = TMP * (1 - rr) + a * rr;
    float b = v_to_PH(adc_v[2]);
    if (b <= 12 && b >= 0)
        PH = PH * (1 - rr) + b * rr;
}
